package com.hllxd.hism.star.basic.service.service.rock;

import com.hllxd.hism.star.basic.service.dao.mapper.mis.TaskExecuteLogMapper;
import com.hllxd.hism.star.basic.service.model.rock.TaskExecuteLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author wuguangxi
 * @Description
 * @Date 2024/4/12 15:40
 */
@Service
public class TaskExecuteLogService {

    @Autowired
    private TaskExecuteLogMapper taskExecuteLogMapper;

    /**
     * 根据任务id，查询执行记录
     * @param taskIds
     * @return
     */
    public Map<String, List<TaskExecuteLog>> findExecuteLogMapByTaskIds(List<String> taskIds){
        if(CollectionUtils.isEmpty(taskIds)){
            return Collections.emptyMap();
        }
        List<TaskExecuteLog> list = taskExecuteLogMapper.findByTaskIds(taskIds);
        // 处理日期
        list.forEach(log -> {
            String dt = log.getDate();

            log.setDate(dt.substring(0, 4) + "-" + dt.substring(4,6) + "-" + dt.substring(6));
        });
        return list.stream()
                .collect(Collectors.groupingBy(TaskExecuteLog::getTaskId));
    }

}
